package 回溯;

import java.util.ArrayList;
import java.util.List;

public class _面试题_08_04_幂集 {
    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        backtrack(res,new ArrayList<Integer>(),nums,0);
        return res;
    }

    private void backtrack(List<List<Integer>> res, ArrayList<Integer> tempList, int[] nums, int begin) {
        if (begin == nums.length) return;
        res.add(new ArrayList<>(tempList));
        for (int i = begin; i < nums.length; i++) {
            tempList.add(nums[i]);
            backtrack(res,tempList,nums,begin);
            tempList.remove(tempList.size() - 1);
        }
    }
}
